from flask import jsonify

class BaseError(Exception):
    """Base Error Class"""

    def __init__(self, code=400, msg='', errors=None):
        Exception.__init__(self)
        self.code = code
        self.msg = msg
        self.errors = errors

    def to_dict(self):
        return {
            'code': self.code,
            'msg': self.msg,
            'errors': self.errors
        }
    
    def jsonify(self):
        return jsonify(self.to_dict())
  
      
class ValidationError(BaseError):
    def __init__(self, msg='参数校验失败', errors=None):
        super().__init__(self)
        self.code = 422
        self.msg = msg
        self.errors = errors


class AddRecordException(Exception):
    """
    Exception for adding record
    """
    def __init__(self, message="新增记录失败"):
        super().__init__(message)


class ModifyRecordException(Exception):
    """
    Exception for modifying record
    """
    def __init__(self, message="修改记录失败"):
        super().__init__(message)


class DelRecordException(Exception):
    """
    Exception for deleting record
    """
    def __init__(self, message="删除记录失败"):
        super().__init__(message)
